/*
 *  Copyright (C) 2010 Matthias Buch-Kromann <mbk.isv@cbs.dk>
 * 
 *  This file is part of the IncrementalParser package.
 *  
 *  The IncrementalParser program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 * 
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.osdtsystem.matrixparser.features;

import java.util.Map.Entry;
import org.osdtsystem.matrixparser.features.keys.FeatureKey;

/**
 *
 * @author Matthias Buch-Kromann <mbk.isv@cbs.dk>
 */
public abstract class AbstractFeatureAggregator implements FeatureAggregator {
    FeatureHandler featureHandler;
    int scorer;

    AbstractFeatureAggregator(FeatureHandler featureHandler, int scorer) {
        this.featureHandler = featureHandler;
        this.scorer = scorer;
    }

    public void addFeature(FeatureKey object) {
        Feature feature = featureHandler.getFeature(object);
        // System.out.println("addFeature: " + feature + "=" + toString(object));
        addFeature(feature);
    }

    public String toString(Object object) {
        if (object instanceof int[]) {
            int[] array = (int[]) object;
            StringBuilder s = new StringBuilder();
            s.append(array[0]);
            for (int i = 1; i < array.length; ++i)
                s.append(":").append(array[i]);
            return s.toString();
        } else {
            return object.toString();
        }
    }


    public void addFeature(FeatureKey feature, float weight) {
        addFeature(featureHandler.getFeature(feature), weight);
    }

    public void addFeature(FeatureKey feature, double weight) {
        addFeature(featureHandler.getFeature(feature), weight);
    }
    
    public void addFeature(Feature feature, double weight) {
        addFeature(feature, (float) weight);
    }

    public void addFeatureVector(FeatureVector fv) {
        for (Entry<Feature,Double> entry : fv) {
            addFeature(entry.getKey(), entry.getValue().floatValue());
        }
    }


    //public int reserveFeatures(int count) {
    //    return featureHandler.reserveFeatures(count);
    //}

}
